package com.cgt.xiaotao.user.controller;

import com.cgt.common.utils.R;
import com.cgt.xiaotao.user.domain.po.City;
import com.cgt.xiaotao.user.service.ICityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "城市接口")
@RestController
@RequestMapping("/city")
@RequiredArgsConstructor
public class CityController {

    private final ICityService cityService;

    @ApiOperation("获取所有省份数据")
    @GetMapping("/provinces")
    public R<List<City>> getAllProvinces() {
        List<City> provinces = cityService.listProvinces();
        return R.ok(provinces);
    }

    @ApiOperation("根据省份ID获取城市数据")
    @GetMapping("/cities/{provinceId}")
    public R<List<City>> getCitiesByProvinceId(@PathVariable Integer provinceId) {
        List<City> cities = cityService.listCitiesByProvinceId(provinceId);
        return R.ok(cities);
    }

    @ApiOperation("根据城市ID获取区县数据")
    @GetMapping("/districts/{cityId}")
    public R<List<City>> getDistrictsByCityId(@PathVariable Integer cityId) {
        List<City> districts = cityService.listDistrictsByCityId(cityId);
        return R.ok(districts);
    }
}
